package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.BdAccLedgerDao;
import com.fdb.efp.nls.service.domain.BdAccLedger;
import com.fdb.efp.nls.service.facade.BdAccLedgerService;
import com.fdb.efp.nls.service.vo.BdAccLedgerVO;
import com.fdb.efp.nls.service.vo.BdNewAccLedgerVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * ServiceImpl: 百度并账文件标准化表
 * <p>
 * 
 * @author ligm
 * @date 2019-03-07
 */
@Service("bdAccLedgerService")
public class BdAccLedgerServiceImpl implements BdAccLedgerService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(BdAccLedgerServiceImpl.class);

	@Autowired
	private BdAccLedgerDao bdAccLedgerDao;

	/**
	 * 新增操作
	 */
	public int insertBdAccLedger(BdAccLedgerVO inBdAccLedgerVo) {
		logger.debug("当前新增数据为:" + inBdAccLedgerVo.toString());
		int num = 0;
		try {
			BdAccLedger bdAccLedger = new BdAccLedger();
			beanCopy(inBdAccLedgerVo, bdAccLedger);
			num = bdAccLedgerDao.insertBdAccLedger(bdAccLedger);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:" + num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(BdAccLedgerVO inBdAccLedgerVo) {
		logger.debug("当前删除数据条件为:" + inBdAccLedgerVo);
		int num = 0;
		try {
			BdAccLedger bdAccLedger = new BdAccLedger();
			beanCopy(inBdAccLedgerVo, bdAccLedger);
			num = bdAccLedgerDao.deleteByPk(bdAccLedger);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inBdAccLedgerVo + "删除的数据条数为" + num);
		return num;
	}

	/**
	 * 更新操作
	 */
	public int updateByPk(BdAccLedgerVO inBdAccLedgerVo) {
		logger.debug("当前修改数据为:" + inBdAccLedgerVo.toString());
		int num = 0;
		try {
			BdAccLedger bdAccLedger = new BdAccLedger();
			beanCopy(inBdAccLedgerVo, bdAccLedger);
			num = bdAccLedgerDao.updateByPk(bdAccLedger);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inBdAccLedgerVo + "修改的数据条数为" + num);
		return num;
	}

	/**
	 * 查询操作
	 */
	public BdAccLedgerVO queryByPk(BdAccLedgerVO inBdAccLedgerVo) {

		logger.debug("当前查询参数信息为:" + inBdAccLedgerVo);
		try {
			BdAccLedger queryBdAccLedger = new BdAccLedger();
			beanCopy(inBdAccLedgerVo, queryBdAccLedger);
			BdAccLedger queryRslBdAccLedger = bdAccLedgerDao.queryByPk(queryBdAccLedger);
			if (Objects.nonNull(queryRslBdAccLedger)) {
				BdAccLedgerVO outBdAccLedgerVo = beanCopy(queryRslBdAccLedger, new BdAccLedgerVO());
				logger.debug("当前查询结果为:" + outBdAccLedgerVo.toString());
				return outBdAccLedgerVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdNewAccLedgerVO> queryAllBdAccLedger(BdAccLedgerVO bdAccLedgerVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<BdNewAccLedgerVO> list = null;
		try {
			List<BdAccLedger> bdAccLedgers = bdAccLedgerDao.queryAllBdAccLedger(bdAccLedgerVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:" + bdAccLedgers.size());
			pageSet(bdAccLedgers, bdAccLedgerVo);
			list = (List<BdNewAccLedgerVO>) beansCopy(bdAccLedgers, BdNewAccLedgerVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdAccLedgerVO> queryAllCurrOrg(BdAccLedgerVO bdAccLedgerVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<BdAccLedger> bdAccLedgers = bdAccLedgerDao.queryAllCurrOrgByPage(bdAccLedgerVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:" + bdAccLedgers.size());
		List<BdAccLedgerVO> list = null;
		try {
			pageSet(bdAccLedgers, bdAccLedgerVo);
			list = (List<BdAccLedgerVO>) beansCopy(bdAccLedgers, BdAccLedgerVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdAccLedgerVO> queryAllCurrDownOrg(BdAccLedgerVO bdAccLedgerVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<BdAccLedger> bdAccLedgers = bdAccLedgerDao.queryAllCurrDownOrgByPage(bdAccLedgerVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:" + bdAccLedgers.size());
		List<BdAccLedgerVO> list = null;
		try {
			pageSet(bdAccLedgers, bdAccLedgerVo);
			list = (List<BdAccLedgerVO>) beansCopy(bdAccLedgers, BdAccLedgerVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}
	
	/**
	 * 
	 * 通过合作方代码和产品类型查询百度并账标准化信息 <br>
	 * 0.1:ludayong:2019年7月19日 下午12:35:13:新增 <br>
	 * @author ludayong
	 * @since 2019年7月19日 下午12:35:13
	 * @date 2019年7月19日 下午12:35:13
	 * @version 0.1
	 */
	@SuppressWarnings("unchecked")
	public List<BdAccLedgerVO> queryBdAccLedgerWithPartnerCodeAndProdType(BdAccLedgerVO bdAccLedgerVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<BdAccLedgerVO> list = null;
		try {
			List<BdAccLedger> bdAccLedgers = bdAccLedgerDao.queryAllBdAccLedger(bdAccLedgerVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:" + bdAccLedgers.size());
			pageSet(bdAccLedgers, bdAccLedgerVo);
			list = (List<BdAccLedgerVO>) beansCopy(bdAccLedgers, BdAccLedgerVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}

	/**
	 * 
	 * 通过存储过程初始化百度并账文件标准化信息 <br>
	 * 0.1:ludayong:2019年7月19日 上午10:16:42:新增 <br>
	 * @author ludayong
	 * @since 2019年7月19日 上午10:16:42
	 * @date 2019年7月19日 上午10:16:42
	 * @version 0.1
	 */
	@Override
	public void initNBdAccLedgerInfo() throws Exception {
		logger.debug("初始化百度并账文件标准化信息开始.....");
		bdAccLedgerDao.initNBdAccLedgerInfo();
		logger.debug("初始化百度并账文件标准化信息结束.....");
	}
}
